package com.dididoctor.doctor.Activity.PatientDetial;

import android.content.Context;

import com.dididoctor.doctor.Activity.ConstantValue;
import com.dididoctor.doctor.Bean.Token;
import com.dididoctor.doctor.Http.MyHttpResponseHandler;
import com.dididoctor.doctor.MV.BasePresenter;
import com.dididoctor.doctor.MV.BusinessClient;
import com.dididoctor.doctor.MV.Response;
import com.dididoctor.doctor.Utils.Util;
import com.loopj.android.http.RequestParams;

import org.apache.http.Header;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @version 2.0
 * @类描述： 登陆页
 * @项目名称：ddgh
 * @类名称： loginActivity
 * @包名称： com.doudoukeji.service.Activity.login
 * @创建人：张强 boy
 * @创建时间：2016/3/7 16:40
 * @修改人：
 * @修改时间：2016/3/7 16:40
 * @修改备注： new parent class(用一句话描述修改了什么)
 */
public class CaseHistoryPresenter extends BasePresenter {
    private CaseHistoryView view;

    public CaseHistoryPresenter(Context context, CaseHistoryView view) {
        super(context, view);
        this.view = view;
    }

    public void lunch(int pageIndex,String clientId) {
//        userId	String	是	用户
//        pageIndex	String	是	页码，第一页从开始
//        pageSize	String	是	页容量
//        token	String	是
//        clientId	String	是	患者id
//        qryType	String	是	定值 1 （医生端）
        RequestParams params = new RequestParams();
        params.put("userId", Token.getUserId());
        params.put("token", Token.getToken());
        params.put("pageSize", ConstantValue.LOAD_MESSAGE_COUNT);
        params.put("pageIndex", pageIndex);
        params.put("clientId", clientId);
        params.put("qryType", "1");
        BusinessClient.post(ConstantValue.medicalistUrl, params, new MyHttpResponseHandler(view) {
            private List<Map<String, String>> maps = new ArrayList<Map<String, String>>();
            private List<CaseHistoryBean> orderBeans = new ArrayList<CaseHistoryBean>();

            @Override
            public void onMyResponse(Response response) {
                if (response.isSucceed()) {
                    maps = response.getListData("medicalist");
//                    "recId":1 病历id
//                    "hosName": abc 就诊医院
//                    "clinicDate": 2016-03-01就诊日期
//                    "dctName": abc 主治医师
//                    "descr": abc 主诉
//                    "type": 1 病历类型 1-系统问诊 2-个人上传
                    for (Map<String, String> map : maps) {
                        CaseHistoryBean messageBean = new CaseHistoryBean();
                        messageBean.setRecId(Util.toString(map.get("recId")));
                        messageBean.setHosName(Util.toString(map.get("hosName")));
                        messageBean.setClinicDate(Util.toString(map.get("clinicDate")));
                        messageBean.setDctName(Util.toString(map.get("dctName")));
                        messageBean.setDescr(Util.toString(map.get("descr")));
                        messageBean.setType(Util.toString(map.get("type")));
                        orderBeans.add(messageBean);
                    }
                    view.getdoctorsucced(orderBeans);
                } else {
                    view.getdoctorsucced(orderBeans);
                }
            }

            @Override
            public void onFailure(int i, Header[] headers, byte[] bytes, Throwable throwable) {
                super.onFailure(i, headers, bytes, throwable);
                view.getdoctorfail();
            }
        });
    }
}
